package com.finance.system.file.controller;


import com.finance.system.file.enums.ParentFolder;
import com.finance.system.support.utils.ResponseUtils;
import com.finance.system.file.entity.PhysicalFile;
import com.finance.system.file.service.PhysicalFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.finance.system.user.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whdong
 * @since 2019-10-14
 */
@RestController
@RequestMapping("/fileSystem")
@Api(tags = "文件系统",description = "文件系统相关接口")
public class FileSystemController extends BaseController {

    @Autowired
    private PhysicalFileService physicalFileService;

    @PostMapping("upload")
    @ApiOperation("上传文件")
    public void upload(MultipartFile file){
        physicalFileService.fromMultipartFile(file, ParentFolder.TEMP_FOLDER);
    }

    @GetMapping("download")
    @ApiOperation("文件下载")
    public void download(Long fileId, HttpServletResponse response){
        PhysicalFile file = physicalFileService.getFile(fileId);
        ResponseUtils.download(response,file,file.getFileSystem().getFileName());

    }


}
